package com.kgc.novel.controller;

import com.kgc.novel.common.Res;
import com.kgc.novel.domain.entity.BookContent;
import com.kgc.novel.domain.param.BookContentParam;
import com.kgc.novel.service.book.BookContentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 32643
 */
@RestController
@RequestMapping("/book/content")
@Slf4j
@Api(tags = "小说内容管理")
@CrossOrigin(originPatterns = "*")
public class BookContentController {

    @Resource
    private BookContentService bookContentService;

    @PostMapping("/list")
    @ApiOperation("查询全部信息")
    public Res getAllList(@RequestBody BookContentParam bookContentParam){
        return bookContentService.selectContentList(bookContentParam);
    }

    @GetMapping("/select/{id}")
    @ApiOperation("查询单个信息")
    public Res getSingle(@PathVariable("id") String id){
        return bookContentService.selectContent(id);
    }

    @PostMapping("/addOrUpdate")
    @ApiOperation("新增或修改信息")
    public Res add(@RequestBody BookContent bookContent){
        if (bookContent.getId() == null){
            return bookContentService.addContent(bookContent);
        }
        return bookContentService.updateContent(bookContent);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除信息")
    public Res delete(@PathVariable("id") String id){
        return bookContentService.deleteContent(id);
    }

    @PostMapping("/deleteAll")
    @ApiOperation("批量删除信息")
    public Res deleteAll(@RequestBody List<String> ids){ // [1,2]
        return bookContentService.deleteAllContent(ids);
    }

}
